package com.qingke.easyjava.jdbc.pojo;

import java.util.ArrayList;
import java.util.List;

public class Question {

	private long id;
	private String value;
	private Player from;
	private int credit;
	private boolean open;
	private int playerId;
	

	private List<Answer> answers =  new ArrayList<Answer>();
	private Answer bestanswer;
	private List<Question> questions;
	
	
	public Question() {
		
	}
	
	public Question(long id,String value,Player from, int credit) {
		this.id = id;
		this.value = value;
		this.from = from;
		this.credit = credit;
		this.open = true;
	}
	
	public Question(long id, String value, Player from, int credit, boolean open, int playerId) {
		super();
		this.id = id;
		this.value = value;
		this.from = from;
		this.credit = credit;
		this.open = true;
		this.playerId = playerId;
	}

	public Question(long id, String value, Player from, int credit, boolean open) {
		super();
		this.id = id;
		this.value = value;
		this.from = from;
		this.credit = credit;
		this.open = true;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Player getFrom() {
		return from;
	}

	public void setFrom(Player from) {
		this.from = from;
	}

	public int getCredit() {
		return credit;
	}

	public void setCredit(int credit) {
		this.credit = credit;
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}
	
	public List<Answer> getAnswers() {
		return answers;
	}

	public void setAnswers(List<Answer> answers) {
		this.answers = answers;
	}

	public Answer getBestanswer() {
		return bestanswer;
	}

	public void setBestanswer(Answer bestanswer) {
		this.bestanswer = bestanswer;
	}

	public String toString() {
        // sample: [SOLVED] 1: WHAT IS YOUR NAME? [5 credits] [2 answers]
        String template = "[%s] %d: [%s] [%d credits] [%d answers]";
        String solved = open ? "SOLVED" : " UNSOLVED ";
        return String.format(template, solved, id, value, credit, answers.size());
    }

    @Override
    public boolean equals(Object obj) {

        if (obj != null) {
            Question qObj = (Question) obj;
            return this.id == qObj.getId();
        }
        return false;
    }

	public int getPlayerId() {
		return playerId;
	}

	public void setPlayerId(int playerId) {
		this.playerId = playerId;
	}

	public List<Question> getQuestions() {
		return questions;
	}

	public void setQuestions(List<Question> questions) {
		this.questions = questions;
	}
}
